package com.jiangtour.converter;

import com.google.gson.Gson;
import com.jiangtour.dto.OrderDTO;
import com.jiangtour.dto.SendInfoDTO;
import com.jiangtour.enums.SendFlagEnum;
import com.jiangtour.form.OrderForm;
import com.jiangtour.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

/**
 * @author Administrator
 * @Title: converter
 * @ProjectName site
 * @Description: TODO
 * @date 2018/12/28/02810:02
 */
@Slf4j
public class OrderForm2OrderDTOConverter {
    public static OrderDTO convert(OrderForm orderForm) {
        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setBuyerAddress(orderForm.getAddress());
        orderDTO.setBuyerName(orderForm.getName());
        orderDTO.setBuyerPhone(orderForm.getPhone());


        SendInfoDTO sendInfoDTO = new SendInfoDTO();
        //如果等于收件
        if (Integer.valueOf(orderForm.getSendFlag()) == SendFlagEnum.COLLECT.getCode()) {
            sendInfoDTO.setAdditionalInfo(orderForm.getExpressInfo());
            orderDTO.setPickUpParts(orderForm.getPickUpParts());
            orderDTO.setSpecId(orderForm.getSpecId());
        } else {
            sendInfoDTO.setAddressee(orderForm.getAddressee());
            sendInfoDTO.setAddresseePhone(orderForm.getAddresseePhone());
            sendInfoDTO.setAddresseeAddress(orderForm.getAddresseeAddress());
            orderDTO.setExpressCompany(orderForm.getExpressCompany());
            orderDTO.setOrderAmount(orderForm.getAmount());
        }

        orderDTO.setAdditional(JsonUtil.toJson(sendInfoDTO));
        orderDTO.setAscriptionId(orderForm.getAscriptionId());
        orderDTO.setFloorNumber(orderForm.getFloorNumber());
        orderDTO.setRemarks(orderForm.getRemarks() != null && !StringUtils.isEmpty(orderForm.getRemarks()) ? orderForm.getRemarks() : "");
        orderDTO.setOrderType(orderForm.getSendFlag());

        return orderDTO;
    }

}
